﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Sispe.Entities;

namespace Sispe.Repository
{
    public class UserProfileRepository : MasterRepository, IUserProfileRepository
    {
        public List<UserProfile> GetAllFromUserProfile()
        {
            var query = from b in context.UserProfiles
                        select b;

            return query.ToList();
        }

        public List<UserProfile> GetAllFromUserProfileByNombre(string userName)
        {
            var query = from b in context.UserProfiles
                        select b;
            if (userName != null && userName != string.Empty && userName != "")
            {
                query = from b in context.UserProfiles
                        where b.UserName.ToUpper().Contains(userName)
                        select b;

                return query.ToList();
            }
            else
            {
                return query.ToList();
            }

            
        }

        public UserProfile GetFromUserProfileById(int id)
        {
            var query = from b in context.UserProfiles
                        where b.UserId.Equals(id)
                        select b;
            return query.SingleOrDefault();
        }

        public void RemoveUserProfile(int id)
        {
            var existe = context.UserProfiles.Find(id);

            if (existe != null)
            {
                context.UserProfiles.Remove(existe);
                context.SaveChanges();
            }
        }


        public UserProfile GetOneUserProfileByUserName(string userName)
        {
            var query = from b in context.UserProfiles
                        select b;
            if (userName != null && userName != string.Empty && userName != "")
            {
                query = from b in context.UserProfiles
                            where b.UserName.Equals(userName)
                            select b;
            }
            return query.FirstOrDefault();
        }
    }
}
